#! /bin/bash

sed -i "s/DUBHE_ENVIRONMENT/$DUBHE_ENVIRONMENT/g" /data/dubhe/*
sed -i "s/REDIS_SERVER/$REDIS_SERVER/g" /data/dubhe/*
sed -i "s/REDIS_PASSWORD/$REDIS_PASSWORD/g" /data/dubhe/*
sed -i "s/MYSQL_SERVICE_HOST/$MYSQL_SERVICE_HOST/g" /data/dubhe/*
sed -i "s/MYSQL_SERVICE_PORT/$MYSQL_SERVICE_PORT/g" /data/dubhe/*
sed -i "s/MYSQL_ROOT_PASSWORD/$MYSQL_ROOT_PASSWORD/g" /data/dubhe/*
sed -i "s/MINIO_ACCESS_KEY/$MINIO_ACCESS_KEY/g" /data/dubhe/*
sed -i "s/MINIO_SECRET_KEY/$MINIO_SECRET_KEY/g" /data/dubhe/*
sed -i "s/BACKEND_PASSWORD/$BACKEND_PASSWORD/g" /data/dubhe/*
sed -i "s/BACKEND_SERVER/$BACKEND_SERVER/g" /data/dubhe/*
sed -i "s/BACKEND_VISUAL_SERVER/$BACKEND_VISUAL_SERVER/g" /data/dubhe/*
sed -i "s/BACKEND_DATA_SERVER/$BACKEND_DATA_SERVER/g" /data/dubhe/*
sed -i "s/BACKEND_DATA_DCM_SERVER/$BACKEND_DATA_DCM_SERVER/g" /data/dubhe/*
sed -i "s/BACKEND_MODEL_CONVERT_SERVER/$BACKEND_MODEL_CONVERT_SERVER/g" /data/dubhe/*
sed -i "s/BACKEND_TERMINAL_HOST/$BACKEND_TERMINAL_HOST/g" /data/dubhe/*
sed -i "s/HARBOR_SERVER/$HARBOR_SERVER/g" /data/dubhe/*
sed -i "s/HARBOR_USERNAME/$HARBOR_USERNAME/g" /data/dubhe/*
sed -i "s/HARBOR_PASSWORD/$HARBOR_PASSWORD/g" /data/dubhe/*
sed -i "s/GRAFANA_SERVER/$GRAFANA_SERVER/g" /data/dubhe/*
sed -i "s/PROMETHEUS_SERVER/$PROMETHEUS_SERVER/g" /data/dubhe/*
sed -i "s/ELASTICSEARCH_SERVER/$ELASTICSEARCH_SERVER/g" /data/dubhe/*
sed -i "s!OPTIMIZE_IMAGE!$OPTIMIZE_IMAGE!g" /data/dubhe/*
sed -i "s!TADL_IMAGE!$TADL_IMAGE!g" /data/dubhe/*
if [ -z $WEB_PROXY_HOST ];then
    sed -i "s/BACKEND_GATEWAY_SERVER/$BACKEND_GATEWAY_SERVER/g" /data/dubhe/*
    sed -i "s/BACKEND_MODEL_MEASURE_SERVER/$BACKEND_MODEL_MEASURE_SERVER/g" /data/dubhe/*
    sed -i "s/BACKEND_DCM_SERVER/$BACKEND_DCM_SERVER/g" /data/dubhe/*
    sed -i "s/MINIO_SERVER/$MINIO_SERVER/g" /data/dubhe/*
    sed -i "s/MINIO_PORT/$MINIO_PORT/g" /data/dubhe/*
else
    sed -i "s/BACKEND_GATEWAY_SERVER:8081/$WEB_PROXY_HOST:30081/g" /data/dubhe/*
    sed -i "s/BACKEND_MODEL_MEASURE_SERVER:8080/$WEB_PROXY_HOST:32760/g" /data/dubhe/*
    sed -i "s/BACKEND_DCM_SERVER/$WEB_PROXY_HOST/g" /data/dubhe/*
    sed -i "s/MINIO_SERVER/$WEB_PROXY_HOST/g" /data/dubhe/*
    # for minio
    sed -i "s/MINIO_PORT/30900/g" /data/dubhe/*
    # for dcm4chee
    sed -i "s/11112/31112/g" /data/dubhe/*
fi
